#!ruby
require 'xmlrpc/client'
require 'pp'

# Trac
tracUser = ENV["TM_TRACUSER"]
tracPassword = ENV["TM_TRACPASSWORD"]    
tracUrl = ENV["TM_TRACURL"]

tracServer = XMLRPC::Client.new2(tracUrl)
tracServer.user = tracUser
tracServer.password = tracPassword

#print tracServer.call("system.methodHelp", "system.getAPIVersion")


# wiki page vars
pageName = "TracTempPageSandbox"           
pageStruct = { "author" => tracUser }

wikiPageString = "= Trac XMLRPC Methods =\n\n----\n"

for i in tracServer.call("system.listMethods")
methodPageHead = <<EOF
= #{i} =
#{tracServer.call("system.methodHelp", i)}
=== method signature(s) - #{i} ===

{{{
EOF

methodSignatures = tracServer.call("system.methodSignature", i)
methodSignatureBlock = ""

for methodSig in methodSignatures 
  
  tempMethodSig = methodSig.split(',')
  tempReturnType = tempMethodSig[0]
  tempMethodSig.delete_at(0) 
  tempParamTypes = tempMethodSig.join(', ')
  methodSignature = "Return type: #{tempReturnType}\nParameter types: #{tempParamTypes}\n"
  methodSignatureBlock = methodSignatureBlock + "#{methodSignature}"
  
end

methodPageFooter = <<EOF
}}}            
----
EOF

methodPage = methodPageHead + methodSignatureBlock + methodPageFooter  

wikiPageString = wikiPageString + methodPage
end
                                
tracServer.call("wiki.putPage", "#{pageName}", wikiPageString, pageStruct)
































